// pages/store/staff.js
import { Team } from '../../model/team.js';
var team = new Team();
import { User } from '../../model/user.js';
var user = new User();
var appInst = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hidden: false,
    price: 0,
    invite_money: 0,
    order_count: 0,
    order_count_one: 0,
    active: 0,
    userInfo: {},
    product_id: 0,
    xiao_name: '总销售额',
    shou_name: '总收入',
    icon: {
      home: '../../utils/image/home.png',
      home_active: '../../utils/image/home-active.png',
      order: '../../utils/image/order.png',
      order_active: '../../utils/image/order-active.png',
      user: '../../utils/image/user.png',
      user_active: '../../utils/image/user-active.png'
    }
  },
  /**
   * 切换菜单
   */
  onChangeTabbar(e) {
    if (e.detail == 1) {
      wx.switchTab({
        url: '../order/order',
      })
    } else if (e.detail == 2) {
      wx.switchTab({
        url: '../user/user',
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '加载中',
    });
    this.getUserInfo();
  },
  /**
   * 修改title
   */
  onShow:function(){
    if(appInst.globalData.appstorename!='美业团')
      appInst.settitle();
  },
  getStaffInfo() {
    team.getTeamUserStaff((res) => {
      this.setData({
        hidden: true,
        price: res.price,
        price_one: res.price_one, 
        invite_money: res.invite_money,
        team: res.team,
        order_count: res.order_count,
        order_count_one: res.order_count_one,
      })
      wx.hideLoading();
    })
  },
  /**
   * 获取用户信息
   */
  getUserInfo() {
    user.getUserInfo((result) => {
      this.setData({
        userInfo: result,
      })
      this.getStaffInfo();
    })
  },
  openProduct() {
    user.getUserInfo((result) => {
      if (result.type == 6 || result.type == 5) {
        wx.redirectTo({
          url: '/pages/store/search',
        })
      }else{
        wx.switchTab({
          url: '/pages/home/home',
        })
      }
    })
    
  },
  openCode() {
    wx.navigateTo({
      url: '../user/team-code',
    })
  },
  openProductKing() {
    wx.navigateTo({
      url: 'product_rank',
    })
  },
  openOrder(e) {
    wx.navigateTo({
      url: 'order_rank?user_id='+e.currentTarget.dataset.user_id,
    })
  },
  // openStore() {
  //   wx.navigateTo({
  //     url: 'owner',
  //   })
  // },
  openLie() {
    wx.navigateTo({
      url: 'user_rank',
    })
  },
  openRank(e) {
    wx.navigateTo({
      url: 'rank?user_id='+e.currentTarget.dataset.userid,
    })
  },
  openInviteRank() {
    wx.navigateTo({
      url: 'invite_rank',
    })
  },
  openStore() {
    wx.navigateTo({
      url: '../store/search',
    })
  },
  /**
   * 用户点击右上角分享
   */
  tocontent: function (options) {
    // 设置转发内容
    // var shareObj = {
    //   path: '/pages/product/type?scene=teamUser-' + this.data.userInfo.id, // 默认是当前页面，必须是以‘/’开头的完整路径
    // };
    // // 来自页面内的按钮的转发
    // if (options.from == 'button') {
    //   // 此处可以修改 shareObj 中的内容
    //   shareObj.path = '/pages/product/type?scene=teamUser-' + this.data.userInfo.id;
    // }
    // // 返回shareObj
    // return shareObj;
    wx.redirectTo({
      url: `/pages/product/product?id=${options.currentTarget.dataset.id}`,
    })
  },
})
